#### SENSITIVITY TEST: Heterogeneous effects between house and senate ####
general_rep <- general %>% 
  filter(party == "R")

general_dem <- general %>% 
  filter(party == "D")

primary_rep <- primary %>% 
  filter(party == "R")

primary_dem <- primary %>% 
  filter(party == "D")

# code control variables
primary_controls_no_party = c("white + incumbent + female + lchars + fchars + race + num_prim_opps + factor(year) + factor(state)")
general_controls_no_party = c("white + incumbent + female + lchars + fchars + race + factor(year) + factor(state)")


mod_primary_rep <- lm(formula(paste(dv_prim, "~", iv_all_names, "+", primary_controls_no_party)),
                        data = primary_rep)

primary_rep_r2 <- get_r2(mod_primary_rep)
mod_primary_rep <- get_clusters(mod_primary_rep)

mod_primary_dem <- lm(formula(paste(dv_prim, "~", iv_all_names, "+", primary_controls_no_party)),
                         data = primary_dem)

primary_dem_r2 <- get_r2(mod_primary_dem)
mod_primary_dem <- get_clusters(mod_primary_dem)

# general congressional elections
mod_general_rep <- lm(formula(paste(dv_gen, "~", iv_all_names, "+", general_controls_no_party)),
                        data = general_rep)


general_rep_r2 <- get_r2(mod_general_rep)
mod_general_rep <- get_clusters(mod_general_rep)

mod_general_dem <- lm(formula(paste(dv_gen, "~", iv_all_names, "+", general_controls_no_party)),
                         data = general_dem)

general_dem_r2 <- get_r2(mod_general_dem)
mod_general_dem <- get_clusters(mod_general_dem)

mods <- list(mod_general_rep, mod_general_dem, mod_primary_rep, mod_primary_dem)
stargazer(mods,
          type = "latex",
          title = "Relationship Between Name Fluency and Vote Share, Heterogeneity by Party",
          style = style,
          star.cutoffs = star.cutoffs,
          star.char = star.char,
          column.labels = c("General (Rep.)", "General (Dem.)", "Primary (Rep.)", "Primary (Dem.)"),
          keep.stat = keep.stat,
          notes = notes,
          keep = keep_congress,
          covariate.labels = covariate.labels_congress,
          font.size = "footnotesize",
          model.names = F,
          add.lines=list(c("Year FE", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark"),
                         c("State FE", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark"),
                         c("N", get_n(mod_general_rep), get_n(mod_general_dem), get_n(mod_primary_rep), get_n(mod_primary_dem)),
                         c("Adj. R-squared", general_rep_r2, general_dem_r2, primary_rep_r2, primary_dem_r2)),
          out = "tables/reg-party.tex",
          label = "tab:reg-party")
